package com.ikun.admin.common.Interceptor.mybatisInterceptor;

import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;

import java.lang.reflect.Field;

/**
 * @ClassName MyBatisUtil
 * @Description:
 * @CreateDate: 2024/6/1 17:56
 */
public class MyBatisUtil {


    // 获取BoundSql的方法
    public static BoundSql getBoundSql(MappedStatement mappedStatement, Object parameterObject) throws NoSuchFieldException, IllegalAccessException {
        Field boundSqlField = mappedStatement.getClass().getDeclaredField("boundSql");
        boundSqlField.setAccessible(true);
        return (BoundSql) boundSqlField.get(mappedStatement);
    }

    public static Boolean isInterceptor(String sql, String condition) {
        return sql.toLowerCase().contains(condition);
    }
}
